package com.snow.campuslink.utils;

import com.snow.campuslink.exceptionhandler.PartFailBusinessException;
import com.snow.campuslink.project.constant.Constant.SysConstant;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.Iterator;

/**
 * 参数校验工具类
 * @author Gaosl
 * @ClassName ParamCheckUtil
 * @date 2021/1/21 14:17
 */
public class ParamCheckUtil {


    public static void checkValidResult(BindingResult result) {
        if (result != null && result.hasErrors()) {
            StringBuilder errorMsg = new StringBuilder();
            Iterator var3 = result.getAllErrors().iterator();
            while(var3.hasNext()) {
                ObjectError error = (ObjectError)var3.next();
                errorMsg.append(error.getDefaultMessage());
            }
            throw new PartFailBusinessException(SysConstant.ResponseCode.PART_FAIL,errorMsg.toString());
        }
    }

}
